﻿//=====================================================================  	
//
//  File:       PackageEvents.cs
//
//  Summary:    This file contains a Control flow sample.
//
//  Date:       06/09/2005
//
//---------------------------------------------------------------------
//  This file is part of the Microsoft SQL Server Code Samples.
//  Copyright (C) Microsoft Corporation.  All rights reserved.
//
//  This source code is intended only as a supplement to Microsoft
//  Development Tools and/or on-line documentation.  See these other
//  materials for detailed information regarding Microsoft code samples.
//
//  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF 
//  ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
//  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//=====================================================================                         

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
using System.Globalization;

namespace Microsoft.SqlServer.SSIS.Samples
{
    sealed class PackageEvents : IDTSEvents
    {
        #region IDTSEvents Members

        void IDTSEvents.OnBreakpointHit(IDTSBreakpointSite breakpointSite, BreakpointTarget breakpointTarget)
        {
            // TODO:  Add PackageEvents.OnBreakpointHit implementation
        }

        void IDTSEvents.OnCustomEvent(TaskHost taskHost, string eventName, string eventText, ref object[] arguments, string subComponent, ref bool fireAgain)
        {
            // TODO:  Add PackageEvents.OnCustomEvent implementation
        }

        bool IDTSEvents.OnError(DtsObject sourceExec, int errorCode, string subComponent, string description, string helpFile, int helpContext, string idofInterfaceWithError)
        {
            string source = ((IDTSName)sourceExec).Name;
            Console.WriteLine(@"IDTSEvents.OnError " + "\nErrorCode " + errorCode
                + "\nSource " + source + "\nSubComponent " + subComponent
                + "\nDescription " + description + "\nIDOfInterfaceWithError "
                + idofInterfaceWithError + "\n");
            return false;
        }

        void IDTSEvents.OnExecutionStatusChanged(Executable exec, DTSExecStatus newStatus, ref bool fireAgain)
        {
            // TODO:  Add PackageEvents.OnExecutionStatusChanged implementation
        }

        void IDTSEvents.OnInformation(DtsObject source, int informationCode, string subComponent, string description, string helpFile, int helpContext, string idofInterfaceWithError, ref bool fireAgain)
        {
            Console.WriteLine(@"IDTSEvents.OnInformation" + "\nSubComponent: "
                + subComponent + "\nDescription: " + description);
        }

        void IDTSEvents.OnPostExecute(Executable exec, ref bool fireAgain)
        {
            TaskHost th = exec as TaskHost;
            Package p = exec as Package;
            DtsContainer dtsCon = exec as DtsContainer;

            if (th == null && p == null)
            {
                Console.WriteLine("IDTSEvents.OnPostExecute - Container: " + dtsCon.Name + "\n");
            }
            else if (th == null)
            {
                Console.WriteLine("IDTSEvents.OnPostExecute - Package: " + p.Name + "\n");
            }
            else if (p == null)
            {
                Console.WriteLine("IDTSEvents.OnPostExecute - TaskHost: " + th.Name + "\n");
            }
        }

        void IDTSEvents.OnPostValidate(Executable exec, ref bool fireAgain)
        {
            TaskHost th = exec as TaskHost;
            Package p = exec as Package;
            DtsContainer dtsCon = exec as DtsContainer;

            if (th == null && p == null)
            {
                Console.WriteLine("IDTSEvents.OnPostValidate - Container: " + dtsCon.Name + "\n");
            }
            else if (th == null)
            {
                Console.WriteLine("IDTSEvents.OnPostValidate - Package: " + p.Name + "\n");
            }
            else if (p == null)
            {
                Console.WriteLine("IDTSEvents.OnPostValidate - TaskHost: " + th.Name + "\n");
            }
        }

        void IDTSEvents.OnPreExecute(Executable exec, ref bool fireAgain)
        {
            TaskHost th = exec as TaskHost;
            Package p = exec as Package;
            DtsContainer dtsCon = exec as DtsContainer;

            if (th == null && p == null)
            {
                Console.WriteLine("IDTSEvents.OnPreExecute - Container: " + dtsCon.Name + "\n");
            }
            else if (th == null)
            {
                Console.WriteLine("IDTSEvents.OnPreExecute - Package: " + p.Name + "\n");
            }
            else if (p == null)
            {
                Console.WriteLine("IDTSEvents.OnPreExecute - TaskHost: " + th.Name + "\n");
            }
        }

        void IDTSEvents.OnPreValidate(Executable exec, ref bool fireAgain)
        {
            TaskHost th = exec as TaskHost;
            Package p = exec as Package;
            DtsContainer dtsCon = exec as DtsContainer;

            if (th == null && p == null)
            {
                Console.WriteLine("IDTSEvents.OnPreValidate - Container: " + dtsCon.Name + "\n");
            }
            else if (th == null)
            {
                Console.WriteLine("IDTSEvents.OnPreValidate - Package: " + p.Name + "\n");
            }
            else if (p == null)
            {
                Console.WriteLine("IDTSEvents.OnPreValidate - TaskHost: " + th.Name + "\n");
            }
        }

        void IDTSEvents.OnProgress(TaskHost taskHost, string progressDescription, int percentComplete, int progressCountLow, int progressCountHigh, string subComponent, ref bool fireAgain)
        {
            Console.WriteLine(@"IDTSEvents.OnProgress " + "\nTaskHost " 
                + taskHost.Name + "\nProgressDescription " 
                + progressDescription + "\nPercentComplete " 
                + percentComplete.ToString(CultureInfo.InvariantCulture) 
                + "\n");
        }

        bool IDTSEvents.OnQueryCancel()
        {
            return false;
        }

        void IDTSEvents.OnTaskFailed(TaskHost taskHost)
        {
            Console.WriteLine(@"IDTSEvents.OnTaskFailed " + taskHost.Name 
                + "\n");
        }

        void IDTSEvents.OnVariableValueChanged(DtsContainer DtsContainer, Variable variable, ref bool fireAgain)
        {
            // TODO:  Add PackageEvents.OnVariableValueChanged implementation
        }

        void IDTSEvents.OnWarning(DtsObject sourceExec, int warningCode, string subComponent, string description, string helpFile, int helpContext, string idofInterfaceWithError)
        {
            string source = ((IDTSName)sourceExec).Name;
            Console.WriteLine(@"IDTSEvents.OnWarning " + "\nWarningCode " 
                + warningCode + "\nSource  " + source + "\nSubComponent " 
                + subComponent + "\nDescription " + description 
                + @"IDOfInterfaceWithError " + idofInterfaceWithError + "\n");
        }

        #endregion
    }
}
